<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ItemAccount.class.php, $Author:  $ */



/** Account item (table `user`)
 * 
 * @package account.item
 * @version $Id: PhpFox_ItemAccount.class.php 383 2008-02-27 22:30:18Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Account_ItemAccount extends DbItem 
{
    
    /** Constructor
     */
    function PhpFox_Mod_Account_ItemAccount()
    {
    	static $aFieldsCache;
    
        parent::DbItem();
        $this->sTable = App::getParam('db','prefix') . "user";
        $this->sId = "id";
        $this->sAlias = "u";
        
 		if (isset($aFieldsCache[$this->sTable]))
        {
            //get fields definitions from cache
            $this->aFields = $aFieldsCache[$this->sTable];
        }
        else
        {              
	        foreach(App::getParam('Mod_Account_userTable') as $var)
	        {
	        	$this->aFields[$var] = $this->sAlias.'.'.$var;
	        }
			$aFieldsCache[$this->sTable] = $this->aFields;
		}
    }
	
	/** Calculate user's age and save it in 'age' propery
	 *  
	 */
	function calcAge()
	{
	    if (!$this->aData['year'])
	    {
	    	$this->aData['age'] = '';
	    	return;	
	    }
		
		$iAge = date('Y') - $this->aData['year'];
	    $iCurrDate = date('m') * 100 + date('d');
	    $iBirthDate = $this->aData['month'] * 100 + $this->aData['day'];
	    if ($iCurrDate < $iBirthDate)
	    {
	        $iAge--;
	    }
	    $this->aData['age'] = $iAge;
	}
	
	/** Calculates user's star sign and save it in 'start_sign' property
	 *  
	 */
	function calcStarSign()
	{
		switch ($this->aData['month'])
		{
		    case 1:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 21) ? 'aquarius' : 'capricorn';
		        break;
		        
		    case 2:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 20) ? 'pisces' : 'aquarius';
		        break;
		        
		    case 3:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 21) ? 'aries' : 'pisces';
		        break;
		        
		    case 4:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 21) ? 'taurus' : 'aries';
		        break;
		        
		    case 5:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 22) ? 'gemini' : 'taurus';
		        break;
		        
		    case 6:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 22) ? 'cancer' : 'gemini';
                break;
		        
		    case 7:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 23) ? 'leo' : 'cancer';
		        break;
		        
		    case 8:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 24) ? 'virgo' : 'leo';
		        break;
		        
		    case 9:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 24) ? 'libra' : 'virgo';
		        break;
		        
		    case 10:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 24) ? 'scorpio' : 'libra';
		        break;
		        
		    case 11:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 23) ? 'sagittarius' : 'scorpio';
		        break;
		        
		    case 12:
		        $this->aData['star_sign'] = ($this->aData['day'] >= 22) ? 'capricorn' : 'sagittarius';
		        break;
	        default:
	            $this->aData['star_sign'] = 'unknown';
       }
	}
}  
?>